//Functions for general control and game displaying


void Start_new() //start a new game, reset the score values and make a new shuffle
{
CLEAR_LCD
LCD_XY(4,1)
LCD_TEXT("BLACK JACK")
LCD_XY(3,2)
LCD_TEXT("START GAME ?")
PINA=0xff;
loop_until_bit_is_clear(ORDEN,yes);
score_player=0;
score_dealer=0;
shuffling(); //Team B
card=0;
card_played=52;
}

void new_game() /*Calls a new game but doesn't reset the player and dealer score
		  and checks if a shuffle hast to be done.
*/
{
if(card>40)
	{
		  shuffling();
			card=0;
			card_played=52;
	}
}

void screen()  //display the player or dealer hand (pantalla)
{
	CLEAR_LCD
	for (i=0;i<11;i++)
		{
		if(card_display[i]!='y')
			{
			if (card_display[i]=='0')
			{
				LCD_XY((screen_cards[i]-1),1)
				LCD_TEXT("10")
			}
			else
				{
				LCD_XY(screen_cards[i],1)
				LCD_CHAR(card_display[i])
				}
			}
		}
	if(card_display[0]=='P')
	{
		LCD_XY(1,2)
		LCD_TEXT("NewCard:Y/N  :")
		LCD_XY(15,2)
		LCD_NUMBER(total_player)
	}
	else
	{
		LCD_XY(15,2)
		LCD_NUMBER(total_dealer)
	}
}

void score() // update and displays the score
{
	CLEAR_LCD
	LCD_XY(1,1)
	LCD_TEXT("SCORE- P:  D:")
	LCD_XY(10,1)
	LCD_NUMBER(score_player)
	LCD_XY(14,1)
	LCD_NUMBER(score_dealer)
	LCD_XY(2,2)
	LCD_TEXT("Play Again:Y/N")
	WAIT_SEC(1)
	do
		{
		notA=~ORDEN;
		if (notA & 0b00100000)
			{
			Start_new();
			ins=1;
			}
		if (notA & 0b10000000)
			{
			new_game();
			ins=1;
			}
		}
	while(ins==0);
	ins=0;
}



